export class CustomError extends Error {
  /**
   * 自定义的错误
   */
  constructor() {
    super();
  }
}

export class InvalidParamError extends CustomError {
  /**
   * 接口参数校验错误
   * @param {string} param 参数名
   */
  constructor(paramName, paramValue) {
    super();
    this.code = 400;
    this.category = '请求参数';
    this.message = `参数${paramName}的输入值${paramValue}格式不正确`;
  }
}

export class AuthError extends CustomError {
  /**
   * 接口鉴权错误
   * @param {string} authorization
   */
  constructor(authorization) {
    super();
    this.code = 401;
    this.category = '接口鉴权';
    this.message = `${authorization}鉴权失败`;
  }
}

export class ForbiddenError extends CustomError {
  /**
   * 权限错误, 服务器理解客户端请求, 但拒绝执行
   * @param {string} errorMessage 错误信息
   */
  constructor(errorMessage) {
    super();
    this.code = 403;
    this.category = '权限';
    this.message = `拒绝执行, ${errorMessage}`;
  }
}

export class ServiceError extends CustomError {
  /**
   * 中台内部服务错误
   * @param {string} serviceName 服务名
   * @param {string} message 错误信息
   */
  constructor(serviceName, message) {
    super();
    this.code = 500;
    this.category = '内部服务';
    this.message = `服务${serviceName}调用失败, ${message}`;
  }
}

export class MysqlError extends CustomError {
  /**
   * 数据库操作错误
   * @param {string} tableName 表名
   */
  constructor(tableName, operation) {
    super();
    this.code = 501;
    this.category = '数据库操作';
    this.message = `${tableName}${operation}操作失败`;
  }
}

export class ThirdServerError extends CustomError {
  /**
   * 请求第三方服务发生的错误
   * @param {string} serverName 第三方服务名称
   * @param {string} resMessage 服务返回信息
   */
  constructor(serverName, resMessage) {
    super();
    this.code = 504;
    this.category = '第三方服务';
    this.message = `第三方服务${serverName}调用失败, 错误信息:${resMessage}`;
  }
}
